package com.niubility.elsaticsearch;


import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class DateBase {
    private static TransportClient client=null;
    private final String HOST = "120.79.152.220";
    private final int PROT = 9300;

    private DateBase() throws UnknownHostException{
        Settings settings = Settings.builder().put("cluster.name", "hehe").build();
        InetSocketTransportAddress node1 = new InetSocketTransportAddress(InetAddress.getByName(HOST),PROT);
        client = new PreBuiltTransportClient(settings);
        client.addTransportAddress(node1);
        //System.out.println("creat client!!");
    }
    public static TransportClient getClient() throws UnknownHostException{
        if(client!=null) return client;
        return new DateBase().client;
    }

    public static void CloseCilent(TransportClient client){
        if (client != null){
            client.close();
        }
    }
}
